package org.linlinjava.litemall.db.util;

import java.util.ArrayList;
import java.util.List;

import org.linlinjava.litemall.db.beans.Constants;
import org.linlinjava.litemall.db.domain.LitemallOrder;

/*
 * 订单流程：下单成功－》支付订单－》发货－》收货
 * 订单状态：0.新建;1.挂起;2.待支付;3.进行中;4.已取餐;5.已完成;6:已取消
 * 退款状态：0.无,1.退款中、2.退款失败(申请不通过)3.退款成功
 * 评价状态: 0.未评价,1.已评价,2.已过期未评价
 *
 */
public class OrderStatusUtil extends OrderUtil {
/*

    public static String orderStatusText(LitemallOrder order) {
        int status = order.getOrderStatus().intValue();

        if (status == 0) {
            return "新建";
        }

        if (status == 1) {
            return "挂起";
        }

        if (status == 2) {
            return "待支付";
        }

        if (status == 3) {
            return "已付款";
        }

        if (status == 4) {
            return "待收货";
        }

        if (status == 5) {
            return "已完成";
        }

        if (status == 6) {
            return "已取消";
        }

        throw new IllegalStateException("orderStatus不支持");
    }


    public static OrderHandleOption build(LitemallOrder order) {
        Short status = order.getOrderStatus();
        OrderHandleOption handleOption = new OrderHandleOption();

        if (status == Constants.ORDER_STATUS_UNPAID) {
            // 如果订单没有被取消，且没有支付，则可支付，可取消
            handleOption.setCancel(true);
            handleOption.setPay(true);
        } else if (status == Constants.ORDER_STATUS_CANCEL) {
            // 如果订单已经取消，则可删除
            handleOption.setDelete(true);
        } else if (status == Constants.ORDER_STATUS_ONGOING ) {
        	if(order.getMadeStatus() == Constants.ORDER_MADE_STATUS_NEW) {
        		// 如果订单已付款，没有发货，则可退款
        		handleOption.setRefund(true);
        	}
        }else if (status == Constants.ORDER_STATUS_PICKUP) {
            // 如果订单已经发货，没有收货，则可收货操作,
            // 此时不能取消订单
            handleOption.setConfirm(true);
        } else if (status == Constants.ORDER_STATUS_FINISHED) {
            // 如果订单已经支付，且已经收货，则可删除、去评论和再次购买
            handleOption.setDelete(true);
            handleOption.setComment(true);
            handleOption.setRebuy(true);
        } else {
            throw new IllegalStateException("status不支持");
        }

        return handleOption;
    }

    public static List<Short> orderStatus(Integer showType) {
        // 全部订单
        if (showType == 0) {
            return null;
        }

        List<Short> status = new ArrayList<Short>();

        if (showType.equals(1)) {
            // 待付款订单
            status.add(Constants.ORDER_STATUS_UNPAID);
        } else if (showType.equals(2)) {
            // 待发货订单
            status.add(Constants.ORDER_STATUS_ONGOING);
        } else if (showType.equals(3)) {
            // 待收货订单
            status.add(Constants.ORDER_STATUS_PICKUP);
        } else if (showType.equals(4)) {
            // 待评价订单
            status.add(Constants.ORDER_STATUS_FINISHED);
//            系统超时自动取消，此时应该不支持评价
//            status.add((short)402);
        } else {
            return null;
        }

        return status;
    }
    
    public static boolean isPayStatus(LitemallOrder litemallOrder) {
        return Constants.ORDER_STATUS_ONGOING == litemallOrder.getOrderStatus().shortValue();
    }
    
    public static boolean isConfirmStatus(LitemallOrder litemallOrder) {
    	return Constants.ORDER_STATUS_FINISHED == litemallOrder.getOrderStatus().shortValue();
    }
    
    public static boolean isCancelStatus(LitemallOrder litemallOrder) {
    	return Constants.ORDER_STATUS_CANCEL == litemallOrder.getOrderStatus().shortValue();
    }
*/

}
